package panel.viewSpots
{
	import assists.HtmlText;
	import assists.Lang;
	import assists.Scale9Grid;
	import assists.SizeManager;
	import assists.TextFieldUtils;
	import assists.URI;
	import assists.resource.ImageResource;
	import assists.resource.ResourceLoader;
	import assists.resource.ResourceLoaderData;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	
	import inerface.IViewSpotDetailPanel;
	
	import main.ClientConstants;
	
	import panel.stars.StarGroup;
	import panel.viewSpots.navigation.BtnClouree;
	
	public class ViewSpotDetail extends Sprite 
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		
		private var _starGroup:StarGroup;
		private var _photoGroup:PhotoSimpleGroup;
		private var _nameTxt:TextField;
		private var _descWordTxt:TextField;
		private var _descTxt:TextField;
		private var _photoIntroTxt:TextField;
		private var _photoTitleIntroTxt:TextField;
		private var _activityWordTxt:TextField;
		private var _activityIntroTxt:TextField;
		private var _evaluateWordTxt:TextField;
		private var _evaluatePersonTxt:TextField;
		private var _ticketTxt:TextField;

		private var _guideBtn:BtnClouree;
		private var _openPhotoRead:Function;
		private var _buyTicketBtn:BtnClouree;
		private var _onOpenNavigation:Function;
		
		public function ViewSpotDetail()
		{
			super();
		}
		
		public function init(stage:Stage, loader:ResourceLoader, lang:Lang,uri:URI = null):void
		{
			
			_stage = stage;
			_loader = loader;
			_lang = lang;
			
			_starGroup = new StarGroup();
			_photoGroup = new PhotoSimpleGroup();
			_nameTxt = new TextField();
			_nameTxt.mouseEnabled = false;
			_nameTxt.autoSize = "left";
			_descWordTxt = new TextField();
			_descWordTxt.mouseEnabled = false;
			_descWordTxt.autoSize = "left";
			_descTxt = new TextField();
			_descTxt.autoSize = "left";
			_descTxt.mouseEnabled = false;
			_descTxt.multiline = true;
			_descTxt.wordWrap = true;
			_photoIntroTxt = new TextField();
			_photoIntroTxt.autoSize = "left";
			_photoIntroTxt.mouseEnabled = false;
			_photoTitleIntroTxt = new TextField();
			_photoTitleIntroTxt.autoSize = "left";
			_photoTitleIntroTxt.mouseEnabled = false;
			_activityWordTxt = new TextField();
			_activityWordTxt.mouseEnabled = false;
			_activityWordTxt.autoSize = "left";
			_activityIntroTxt = new TextField();
			_activityIntroTxt.mouseEnabled = false;
			_activityIntroTxt.autoSize = "left";
			_evaluateWordTxt = new TextField();
			_evaluateWordTxt.mouseEnabled = false;
			_evaluateWordTxt.autoSize = "left";
			_evaluatePersonTxt = new TextField();
			_evaluatePersonTxt.autoSize = "left";
			_ticketTxt = new TextField();
			_ticketTxt.autoSize = "left";
			_ticketTxt.mouseEnabled = false;
			
			_photoGroup.addEventListener(MouseEvent.CLICK,clickPhotoHandler);
			
			_loader.load([new ResourceLoaderData("assets/viewSpot/titleBlue.png"),new ResourceLoaderData("assets/viewSpot/guideButton.png")],new Function,render);
		}
		
		protected function clickPhotoHandler(event:MouseEvent):void
		{
			trace("open photoread");
			_openPhotoRead();
		}
		
		private function render():void
		{
			
			
		   TextFieldUtils.setHtmlText(_nameTxt,HtmlText.format("<b>赤山法华院</b>",0xfff100,28));
		   _nameTxt.x = (_stage.stageWidth - _nameTxt.width)/2;
		   _nameTxt.y = _stage.stageHeight * ClientConstants.HOME_UP_PER + 10;
		   this.addChild(_nameTxt);
		   
			_guideBtn = new BtnClouree();
			_guideBtn.label(HtmlText.format("景区导航",0,18));
			_guideBtn.autoSize(_stage.stageWidth * 0.25);
			
			
			_buyTicketBtn = new BtnClouree();
			_buyTicketBtn.label(HtmlText.format("预定门票",0,18));
			_buyTicketBtn.autoSize(_stage.stageWidth * 0.25);
		_guideBtn.scaleX = _guideBtn.scaleY = _buyTicketBtn.scaleX = _buyTicketBtn.scaleY = (_stage.stageWidth / 3)/_guideBtn.width;
		
			
			_guideBtn.y = _nameTxt.y + _nameTxt.height;
			_guideBtn.x = (_stage.stageWidth/2 - _guideBtn.width) * 0.5;
			_buyTicketBtn.y = _guideBtn.y;
			_buyTicketBtn.x = _stage.stageWidth/2 + (_stage.stageWidth/2 - _buyTicketBtn.width) * 0.5;
			
		   TextFieldUtils.setHtmlText(_descWordTxt,HtmlText.format("介绍",0xffffff,22));
		   _descWordTxt.x = _stage.stageWidth * 0.07;
		   _descWordTxt.y = _guideBtn.y + _guideBtn.height + 10;
		   this.addChild(_descWordTxt);
		   
		   TextFieldUtils.setHtmlText(_ticketTxt,HtmlText.format("(票价:￥120)",0xffffff));
		   _ticketTxt.y = _nameTxt.y + _nameTxt.height - _ticketTxt.height;
		   _ticketTxt.x = _nameTxt.x + _nameTxt.width;
		   this.addChild(_ticketTxt);
		   
		   _descTxt.width = _stage.stageWidth - ( _descWordTxt.x +　_descWordTxt.width) * 2
		   TextFieldUtils.setHtmlText(_descTxt,HtmlText.format("  这里是介绍这里是介绍这里是介绍这里是介绍这里是介绍这里是介绍这里是介绍这里是介绍这里是介绍这里是介绍这里是介绍这里是介绍",0xffffff,18));
		   _descTxt.x = _stage.stageWidth * 0.05 + _descWordTxt.width;
		   _descTxt.y = _descWordTxt.y + _descWordTxt.height;
		   this.addChild(_descTxt);
		   
		   _photoIntroTxt.width =  _stage.stageWidth - ( _descWordTxt.x) * 2
		   TextFieldUtils.setHtmlText(_photoIntroTxt,HtmlText.format("网友美图欣赏",0xffffff,22));
		   _photoIntroTxt.x = _descWordTxt.x;
		   _photoIntroTxt.y = _descTxt.y + _descTxt.height + distance;
		   this.addChild(_photoIntroTxt);
		   
		   TextFieldUtils.setHtmlText(_photoTitleIntroTxt,HtmlText.format("（您上传的美图，每月景区将会评选优秀作品）",0xffff11,14));
		   _photoTitleIntroTxt.x = _photoIntroTxt.x;
		   _photoTitleIntroTxt.y = _photoIntroTxt.y + _photoIntroTxt.height;
		   this.addChild(_photoTitleIntroTxt);
		   
		   _photoGroup.show(["assets/viewSpot/chengshantou.jpg","assets/viewSpot/fahuayuan.jpg","assets/viewSpot/liugongdao.jpg","assets/viewSpot/fahuayuan.jpg"],_loader,_stage);
		   this.addChild(_photoGroup);
		   _photoGroup.y = _photoTitleIntroTxt.y + _photoTitleIntroTxt.height;
		   
		   TextFieldUtils.setHtmlText(_activityWordTxt,HtmlText.format("本景区近期活动",0xffffff,22));
		   _activityWordTxt.x = _descWordTxt.x;
		   _activityWordTxt.y = _photoGroup.y + _photoGroup.height + distance;
		   this.addChild(_activityWordTxt);
		   
		   TextFieldUtils.setHtmlText(_activityIntroTxt,HtmlText.format("本景区近期活动 樱桃节 樱花节 参与有大奖\n来逛庙会吧，各种好玩好吃应有尽有！",0xffffff,18));
		   _activityIntroTxt.x = _descWordTxt.x;
		   _activityIntroTxt.y = _activityWordTxt.y + _activityWordTxt.height;
		   this.addChild(_activityIntroTxt);
		   
		   TextFieldUtils.setHtmlText(_evaluateWordTxt,HtmlText.format("游客评价:",0xffffff,22));
		   _evaluateWordTxt.x = _descWordTxt.x;
		   _evaluateWordTxt.y = _activityIntroTxt.y + _activityIntroTxt.height + distance;
		   this.addChild(_evaluateWordTxt);
		   
		   _starGroup.starLevel = 10;
		   this.addChild(_starGroup);
		   _starGroup.y = _evaluateWordTxt.y + (_evaluateWordTxt.height - _starGroup.height)/2;
		   _starGroup.x = _evaluateWordTxt.x + _evaluateWordTxt.width + _stage.stageWidth * 0.04;
		   
		   TextFieldUtils.setHtmlText(_evaluatePersonTxt,HtmlText.format("<a href='http://www.baidu.com'><u>(999人评价)</u></a>",0xffffff,18));
		   _evaluatePersonTxt.x = _starGroup.x +　_starGroup.width;
		   _evaluatePersonTxt.y =  _evaluateWordTxt.y
		   this.addChild(_evaluatePersonTxt);
		   
		   
//		   设置标题背景位置
		   var back1:Bitmap = _loader.getImage("assets/viewSpot/titleBlue.png");
		   var scrid9:Scale9Grid = new Scale9Grid(back1.bitmapData,10,10);
		   scrid9.height = _descWordTxt.height;
		   scrid9.width = _descWordTxt.width + backWid;
		   this.addChildAt(scrid9,0);
		   SizeManager.toPos(scrid9,_descWordTxt);
		   
		   var scrid92:Scale9Grid = new Scale9Grid(back1.bitmapData,10,10);
		   scrid92.height = _photoIntroTxt.height;
		   scrid92.width = _photoIntroTxt.width + backWid;
		   this.addChildAt(scrid92,0);
		   SizeManager.toPos(scrid92,_photoIntroTxt);
		   
		   var scrid93:Scale9Grid = new Scale9Grid(back1.bitmapData,10,10);
		   scrid93.height = _activityWordTxt.height;
		   scrid93.width = _activityWordTxt.width + backWid;
		   this.addChildAt(scrid93,0);
		   SizeManager.toPos(scrid93,_activityWordTxt);
		   
		   this.addChild(_buyTicketBtn);
		   this.addChild(_guideBtn);
		   _guideBtn.addEventListener(MouseEvent.CLICK,clickGuideBtnHandler);
		   _buyTicketBtn.addEventListener(MouseEvent.CLICK,butTicketHandler);
		   
		}
		
		protected function butTicketHandler(event:MouseEvent):void
		{
			navigateToURL(new URLRequest("tel:13287870801"));
		}
		
		protected function clickGuideBtnHandler(event:MouseEvent):void
		{
			trace("click btn");
			_onOpenNavigation();
		}
		
		private function get backWid():Number
		{
			return _stage.stageHeight * 0.02;
		}
		 
		private function get distance():int
		{
			return _stage.stageHeight * 0.03;
		}
		
		public function set openPhotoRead(value:Function):void
		{
			_openPhotoRead = value;
		}
		
		public function set onOpenNavigation(value:Function):void
		{
			_onOpenNavigation = value;
		}
		
		public function clear():void
		{
			_guideBtn.removeEventListener(MouseEvent.CLICK,clickGuideBtnHandler);
			_buyTicketBtn.removeEventListener(MouseEvent.CLICK,butTicketHandler);
		}
	}
}